package iot.entity;

import com.datastax.driver.core.LocalDate;
import com.datastax.driver.core.utils.UUIDs;
import com.datastax.driver.mapping.annotations.ClusteringColumn;
import com.datastax.driver.mapping.annotations.PartitionKey;
import com.datastax.driver.mapping.annotations.Table;
import com.datastax.driver.mapping.annotations.Transient;
import io.netty.util.internal.ReflectionUtil;
import iot.disruptor.EventData;
import iot.jtt808.DataPack;
import iot.jtt808.terminal.TerminalRegister;
import org.springframework.beans.BeanUtils;
import org.springframework.util.ReflectionUtils;

import java.time.ZoneId;
import java.util.Date;
import java.util.UUID;

/**
 * Created by dave on 18-7-21 上午9:46.
 */
@Table(keyspace = "iot", name = "registration")
public class Registration implements EventData<Registration> {
    @ClusteringColumn(1)
    private String sim;
    private int provinceId;
    private int cityId;
    private String makerId;
    private String model;
    private String deviceId;
    private int colorId;
    private String vin;
    private String license;
    @PartitionKey
    private LocalDate date;
    @ClusteringColumn
    private UUID uuid;
    @Transient
    private Date time;

    public static Registration fromDataPack(DataPack<TerminalRegister> dp) {
        Registration r = new Registration();
        TerminalRegister tr = dp.getBody();
        r.sim = dp.getSim();
        r.provinceId = tr.getProvinceId() * 10000;
        r.cityId = r.provinceId + tr.getCityId();
        r.makerId = tr.getMakerId();
        r.model = tr.getModel();
        r.deviceId = tr.getDeviceId();
        r.colorId = tr.getColorId();
        r.vin = tr.getVin();
        r.license = tr.getLicense();
        r.time = new Date();
        r.date = LocalDate.fromMillisSinceEpoch(r.time.toInstant().atZone(ZoneId.systemDefault()).toLocalDate().toEpochDay());
        r.uuid = UUIDs.timeBased();
        return r;
    }

    public String getSim() {
        return sim;
    }

    public void setSim(String sim) {
        this.sim = sim;
    }

    public int getProvinceId() {
        return provinceId;
    }

    public void setProvinceId(int provinceId) {
        this.provinceId = provinceId;
    }

    public int getCityId() {
        return cityId;
    }

    public void setCityId(int cityId) {
        this.cityId = cityId;
    }

    public String getMakerId() {
        return makerId;
    }

    public void setMakerId(String makerId) {
        this.makerId = makerId;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public int getColorId() {
        return colorId;
    }

    public void setColorId(int colorId) {
        this.colorId = colorId;
    }

    public String getVin() {
        return vin;
    }

    public void setVin(String vin) {
        this.vin = vin;
    }

    public String getLicense() {
        return license;
    }

    public void setLicense(String license) {
        this.license = license;
    }

    public LocalDate getDate() {
        return date;
    }

    public void setDate(LocalDate date) {
        this.date = date;
    }

    public UUID getUuid() {
        return uuid;
    }

    public void setUuid(UUID uuid) {
        this.uuid = uuid;
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }
}
